#include <REGX52.H>

void Delayxms(unsigned int delay){	// ms
	unsigned char i, j;
	while(delay--){
	i = 2;
	j = 199;
	do
	{
		while (--j);
	} while (--i);
	}
}

unsigned char LED_num= 0;
void main(){
	P2 = ~(0X01);
	while(1){
		// <<
		if (P3_1 == 0){// if pressed
			Delayxms(20);
			while(P3_1 == 0);
			Delayxms(20);
			/*
			0000 0001		0X01<<0
			0000 0010		0X01<<1
			0000 0100		0X01<<2
			*/
			LED_num++;
			if(LED_num == 8){
			LED_num = 0;
			}
			P2 = ~(0X01<<LED_num);
	
		}
		//  >>
		if (P3_0 == 0){// if pressed
			Delayxms(20);
			while(P3_0 == 0);
			Delayxms(20);	
			
			if(LED_num == 0){
			LED_num = 7;
			}else{
			LED_num--;	
			}
	
			P2 = ~(0X01<<LED_num);
	
		}
	}
}
